Skip to content

gh-160513: Call connection_lost() when start_tls() handshake is lost - #160514

Open
gpshead wants to merge 2 commits into
python:mainfrom
gpshead:scanfix-sslproto-a6ziafvt
Open

gpshead wants to merge 2 commits into
python:mainfrom
gpshead:scanfix-sslproto-a6ziafvt

Conversation

@gpshead

@gpshead gpshead commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

SSLProtocol.connection_lost() did not forward to the application protocol while the handshake was in progress. That is right for create_connection(ssl=...) and create_server(ssl=...), where the protocol has not had connection_made() yet, but not for start_tls(), where it has. The method now decides on the application protocol state alone, which already tells the two cases apart (STATE_INIT vs. STATE_CON_MADE). After a connection reset, a handshake timeout or a cancelled start_tls() the protocol now gets connection_lost(), and StreamWriter.wait_closed() completes instead of waiting forever.

A protocol passed to start_tls() now gets a connection_lost() call in these cases that it did not get before (with None when start_tls() was cancelled); that is the documented contract. The reset test accepts any ConnectionError because it was only run on selector event loops.

Fixes #160513

ANT-2026-A6ZIAFVT ANT-2026-4SKWM05E

… lost

SSLProtocol.connection_lost() did not notify the application protocol
while a handshake was in progress, even when start_tls() had handed
over a protocol that had already seen connection_made().  With streams
this left StreamWriter.wait_closed() waiting forever.
Comment thread Lib/test/test_asyncio/test_sslproto.py Outdated
@gpshead gpshead moved this from Todo to In Progress in Sprint Oct 25, 2026
Wait for on_con_lost with LOOPBACK_TIMEOUT, shorter than the
SHORT_TIMEOUT wrapping the whole client, so a missing connection_lost()
fails at that line.  Use SHORT_TIMEOUT instead of a hard-coded 10 in the
streams test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

start_tls() does not call connection_lost() when the handshake is aborted

2 participants